<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use common\models\MktPost;
use common\models\MktUser;

?>
<!--
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
-->
<style>
ul.pagination {margin: 10px; padding: 10; list-style-type: none; text-align: center; }
ul.pagination li {display: inline; margin: 0 30px;}
ul.pagination li.disabled {display: none;}
ul.pagination li a {text-decoration: none;color: #999999 !important;margin: 0 10px;padding: 0 10px;}
</style>

<?php yii\widgets\Pjax::begin(); ?>
<header class="scr-header po-f">
    <div class="itms itms2" id="dz-btn"><span style="padding-right: 10px;">区域</span></div>
    <div class="itms itms2" id="hy-btn"><span style="padding-right: 10px;">行业</span></div>
</header>

<section class="tc-top" id="dz-main">
    <div class="weui_cells weui_cells_radio">

        <?php foreach($areaFirstLevelNodes as $node) { ?>
        <label class="weui_cell weui_check_label" for="radio1-<?php echo $node->id; ?>">
            <div class="weui_cell_bd weui_cell_primary">
                <p><?php echo $node->theTitle; ?></p>
            </div>
            <div class="weui_cell_ft">
                <input class="weui_check" name="radio1" id="radio1-<?php echo $node->id; ?>" type="radio" value="<?php echo $node->id; ?>">
                <span class="weui_icon_checked"></span>
            </div>
        </label>
        <?php } ?>
    </div>
</section>

<section class="tc-top" id="hy-main">
    <div class="weui_cells weui_cells_radio">
        <?php foreach($industryFirstLevelNodes as $node) { ?>
        <label class="weui_cell weui_check_label" for="radio2-<?php echo $node->id; ?>">
            <div class="weui_cell_bd weui_cell_primary">
                <p><?php echo $node->theTitle; ?></p>
            </div>
            <div class="weui_cell_ft">
                <input class="weui_check" name="radio2" id="radio2-<?php echo $node->id; ?>" type="radio" value="<?php echo $node->id; ?>">
                <span class="weui_icon_checked"></span>
            </div>
        </label>
        <?php } ?>

    </div>
</section>

<script type="text/javascript">

//var window.swipeUp = 1;

$('#dz-main input:radio').change(function () {
    $('#dz-main').removeClass('show');
    $('#area_id').val($('input[name="radio1"]:checked').val());
    $('input[name=page]').val(1);
    $( "#shadow_form").submit();

});
$('#hy-main input:radio').change(function () {
    $('#hy-main').removeClass('show');
    $('#industry_id').val($('input[name="radio2"]:checked').val());
    $('input[name=page]').val(1);
    $( "#shadow_form").submit();
});

$(function () {
    //地址
    $("#dz-btn").swipe({
        tap: function () {
            $('#hy-main').removeClass('show');
            $('#dz-main').toggleClass('show')
        }
    });
    //行业
    $("#hy-btn").swipe({
        tap: function () {
            $('#dz-main').removeClass('show');
            $('#hy-main').toggleClass('show');
        }
    });

    $("#market").swipe({
        swipeUp:function(){
            var ch = $("#market").height();
            var wh = $('body').height();
            var top = $("#market").parent().scrollTop();
            var hh = ch - wh;
            if(top >= hh)
            {
                frmwebm.toast("数据加载中...", 50);
                $('input[name=page]').val( parseInt($('input[name=page]').val()) + 1 );
                $("#shadow_form").submit();
            }
        },

        swipeDown:function(){
            var top = $("#market").scrollTop();
            if(top <= 0)
            {
                frmwebm.toast("数据加载中...", 50);
                $('input[name=page]').val( parseInt($('input[name=page]').val()) - 1 );
                $("#shadow_form").submit();
            }
        }

    });

})

</script>

<!--主体-->
<section class="page scr-page">
    <div class="weui_panel weui_panel_access">
        <div id='mylist' class="weui_panel_bd">

            <?php echo yii\widgets\ListView::widget([
                'dataProvider' => $dataProvider,
                'itemView' => '_item',
                'layout' => YII_ENV_DEV ? "{summary}\n{items}\n{pager}" : "{items}",
                'id' => 'mylistview',
                'emptyText' => '',
                'pager' => [
                    'firstPageLabel' => false,
                    'lastPageLabel' => false,
                    'prevPageLabel' => '上页',
                    'nextPageLabel' => '下页',
                    'maxButtonCount' => 0,
                ],

            ]) ?>

            <div class="<?php echo YII_ENV_DEV ? '' : 'hide' ?> ">
                <?php $form = ActiveForm::begin(['method' => 'get', 'id'=>'shadow_form', 'options'=>['data-pjax' => true], ]); ?>
                <?php if (!isset($_GET['page'])): ?>
                    <input type="hidden" name="page" value="1">
                <?php endif; ?>

                <?= $form->field($searchModel, 'industry_id') -> textInput(['id' => 'industry_id']) ?>
                <?= $form->field($searchModel, 'area_id') -> textInput(['id' => 'area_id']) ?>

                <?php ActiveForm::end(); ?>
            </div>

        </div>
    </div>
</section>
<?php yii\widgets\Pjax::end(); ?>

<?php
/*
 *
<!--
        <a href="market/woman.jsp" class="weui_media_box weui_media_appmsg">
            <div class="weui_media_hd">
                <img class="weui_media_appmsg_thumb" src="resources/images/avatar/tx.jpg" alt="">
            </div>
            <div class="weui_media_bd">
                <h4 class="weui_media_title"><span class="name">王可(女)</span>艺米沙画</h4>
                <p class="weui_media_desc">总经理</p>
            </div>
        </a>
        <a href="market/man2.jsp" class="weui_media_box weui_media_appmsg">
            <div class="weui_media_hd">
                <img class="weui_media_appmsg_thumb" src="resources/images/avatar/tx.jpg" alt="">
            </div>
            <div class="weui_media_bd">
                <h4 class="weui_media_title"><span class="name">王可(男)</span>艺米沙画</h4>
                <p class="weui_media_desc">总经理</p>
            </div>
        </a>
        <a href="market/man.jsp" class="weui_media_box weui_media_appmsg">
            <div class="weui_media_hd">
                <img class="weui_media_appmsg_thumb" src="resources/images/avatar/tx.jpg" alt="">
            </div>
            <div class="weui_media_bd">
                <h4 class="weui_media_title"><span class="name">王可(好友)</span>艺米沙画</h4>
                <p class="weui_media_desc">总经理</p>
            </div>
        </a>
-->


$("#market").swipe({
    swipeUp:function(){
		var ch = $("#market").height();
		var wh = $('body').height();
		var top = $("#market").parent().scrollTop();
		var hh = ch - wh;
		if(top >= hh)
		{
			frmwebm.toast("数据加载中...", 2000);
			var kk = $("#market").parent().scrollTop();
			var kkk = $("#market").parent().height()-110;
			var obj = $("#market").find(".weui_panel .weui_panel_bd");
			
			obj.append(fff(11));
			obj.append(fff(22));
			obj.append(fff(221));
			obj.append(fff(222));
			obj.append(fff(223));
			obj.append(fff(224));
			obj.append(fff(225));
			obj.append(fff(226));
			obj.append(fff(227));
			obj.append(fff(229));
			obj.append(fff(220));
			
			$("#market").parent().scrollTop(kk+kkk);
		}
    },
	swipeDown:function(){
		var top = $("#market").scrollTop();
		if(top <= 0)
		{
			frmwebm.toast("下拉刷新...", 2000);
			
			var obj = $("#market").find(".weui_panel .weui_panel_bd");
			obj.prepend(fff(11));
			obj.prepend(fff(22));
			obj.prepend(fff(221));
			obj.prepend(fff(222));
			obj.prepend(fff(223));
			obj.prepend(fff(224));
			obj.prepend(fff(225));
			obj.prepend(fff(226));
			obj.prepend(fff(227));
			obj.prepend(fff(229));
			obj.prepend(fff(220));
		}
	}
});
function fff(id)
{
	var html = '<a href="javascript:void(0);" class="weui_media_box weui_media_appmsg">';
	html += '	<div class="weui_media_hd">';
	html += '		<img class="weui_media_appmsg_thumb" src="resources/images/avatar/tx.jpg" alt="">';
	html += '	</div>';
	html += '	<div class="weui_media_bd">';
	html += '		<h4 class="weui_media_title"><span class="name">'+id+'</span>艺米沙画</h4>';
	html += '		<p class="weui_media_desc">总经理</p>';
	html += '	</div>';
	html += '</a>';
	return html;
}

    $("#market").swipe({
        swipeUp: function () {
            var ch = $("#market").height();
            var wh = $('body').height();
            var top = $("#market").parent().scrollTop();
            var hh = ch - wh;
            if (top >= hh) {
                frmwebm.toast("数据加载中...", 2000);
                $('input[name=page]').val( parseInt($('input[name=page]').val()) + 1 );
                getLatestUsersAjax(1);
            }
        },

        swipeDown:function(){
            var top = $("#market").scrollTop();
            if(top <= 0)
            {
                frmwebm.toast("数据加载中...", 2000);
                $('input[name=page]').val( parseInt($('input[name=page]').val()) - 1 );
                getLatestUsersAjax(0);
            }
        }

    });


function getCurrentUrl(){
    return window.location.href;
}

function getCurrentUrlWithoutParams(){
    return 'http://' + window.location.hostname + window.location.pathname;
}

function addRow(obj, row, isAppend)
{
    var params = { r:'wap/market-profile', 'id':row['id'] };
    var url = getCurrentUrlWithoutParams() + '?' + $.param( params );

    var html = '<div><a href="' + url + '" class="weui_media_box weui_media_appmsg">';
    html += '	<div class="weui_media_hd">';
    html += '		<img class="weui_media_appmsg_thumb" src="' + row['headimgurl'] +'" alt="">';
    html += '	</div>';
    html += '	<div class="weui_media_bd">';
    html += '		<h4 class="weui_media_title"><span class="name">' + row['name'] + '</span>' + row['company'] + '</h4>';
    html += '		<p class="weui_media_desc">' + row['duty'] + '</p>';
    html += '	</div>';
    html += '</a></div>';

    if (isAppend)
    {
        obj.append(html);
    } else {
        obj.prepend(html);        
    }
}

function toArray($a) {
    return $a.reduce(function(obj, item) {
        obj[item.name] = item.value;
        return obj;
    }, {});
}

function alertArray($a) {
    $.each($a, function(index, value) {
        alert(index + ': ' + value);
    });
}

function getLatestUsersAjax(swipeUp) {

    var args = {
        'classname': '\\common\\models\\MktUser',
        'funcname': 'getLatestUsersAjax',
        'params': {
            'id': 1,
            'name': 'jack',
        }
    };

    var formParams = toArray($('#shadow_form').serializeArray());
    delete formParams['r'];

    $.ajax({
        url: "<?= Url::to(['/wap/ajax-broker']); ?>" + '&' + $.param(formParams),
        type: "GET",
        cache: false,
        dataType: "json",
        data: "args=" + JSON.stringify(args),
        success: function (resp) {
            if (resp['code'] != 0) {
                alert("handle error");
                return;
            }
            if (resp['data'].length == 0) {
                frmwebm.toast("请休息一会...", 2000);
                return;
            }
            if (swipeUp == 1)
            {
                for (i = 0; i < resp['data'].length; ++i) {
                    $row = resp['data'][i];
                    //alertArray($row);
                    var kk = $("#market").parent().scrollTop();
                    var kkk = $("#market").parent().height()-110;
                    addRow($("#mylistview"), $row, true);
                    $("#market").parent().scrollTop(kk+kkk);
                }
            } else {
                for (i = 0; i < resp['data'].length; ++i) {
                    $row = resp['data'][i];
                    //alertArray($row);
                    addRow($("#mylistview"), $row, false);
                }
            }
        },
        error: function () {
            //alert('send error');
        }
    });
}
*/
